package 命令模式;

import 命令模式.功能键.FunctionButton;
import 命令模式.命令类.Command;
import 命令模式.命令类.ExitCommand;
import 命令模式.命令类.HelpCommand;

import java.io.*;
import java.util.Properties;


public class Client {
    public static void main(String[] args) throws IOException {
        FunctionButton button = new FunctionButton();

        //要实现的功能
        String command=readProperties("command");//读取配置文件
        if (command!=null&&command.equals("exit")){
            button.setCommand(new ExitCommand());
            //执行execute
            button.click();
        }else if (command!=null&&command.equals("help")){
            button.setCommand(new  HelpCommand());
            //执行execute
            button.click();
        }else {
            System.out.println("配置文件输出错误");
        }
    }

    /**
     * 读取配置文件
     * @param command
     * @return
     */
    public static String readProperties(String command) throws IOException {
        String val=null;
        FileInputStream is = null;
        try {
            File file = new File("src/命令模式/application.properties");
//            E:\File\设计模式\Designer\src\命令模式\application.properties
            is = new FileInputStream(file);
            Properties properties = new Properties();
            properties.load(is);
            val = properties.getProperty("command");
            return val;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return val;
        } catch (IOException e) {
            e.printStackTrace();
            return val;
        }finally {
            is.close();
        }
    }

}
